<template>
  <div class="system-info">
    <div class="main-middle">
      <!-- 查询条件 -->
      <el-row class="table-selbox" v-if="btnSel">
        <!-- 查询条件表单 -->
        <el-form :inline="true" :model="formInline" >
          <!-- 流程编号 -->
          <el-form-item label="流程编号">
            <el-input v-model.trim="formInline.flowCode" clearable></el-input>
            <!-- <el-select
              v-model="formInline.flowId"
              filterable
              auto-complete="off"
              placeholder="请选择"
              style="width:150px;"
            >
              <el-option label="无" value></el-option>
              <el-option
                v-for="(item,index) in flowList"
                :key="index"
                :label="item.flowName"
                :value="item.flowId"
              ></el-option>
            </el-select> -->
          </el-form-item>
          <el-form-item label="发起人">
            <!-- 员工选择框子组件 -->
            <user-sel :users="users" @seluser="selUser"></user-sel>
          </el-form-item>
          <!-- 搜索 -->
          <el-form-item>
            <el-button icon="el-icon-search" @click="selHandle">搜索</el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <!-- 数据列表 -->
      <el-table :data="menusData" border style="width: 100%" height="640" ref="menusData">
        <!-- 流程编号 -->
        <el-table-column :show-overflow-tooltip="true" prop="flowCode" label="流程编号"></el-table-column>
        <!-- 发起人 -->
        <el-table-column label="发起人" align="center" width="120">
          <template slot-scope="scope">{{ scope.row.flowOriginator | getName(users) }}</template>
        </el-table-column>
        <!-- 工单优先级 -->
        <!-- <el-table-column align="center" label="优先级" width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.flowPriority === 0">
              普通
            </span>
            <span v-if="scope.row.flowPriority === 1" style="color:#0079ff;">
              重要
            </span>
            <span v-if="scope.row.flowPriority === 2" style="color:red;">
              紧急
            </span>
          </template>
        </el-table-column> -->
        <!-- 流程状态 -->
        <el-table-column align="center" label="流程状态" width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.status === 3 || scope.row.status === 2">
              待审批
            </span>
            <span v-if="scope.row.status === 5" style="color:red;">
              被驳回
            </span>
          </template>
        </el-table-column>
          <!-- 申请日期 时间格式过滤 -->
        <el-table-column label="申请日期" align="center">
          <template slot-scope="scope">{{ scope.row.createTime | filterTime }}</template>
        </el-table-column>
        <!-- 操作列 -->
        <el-table-column
          label="管理"
          fixed="right"
          align="center"
          width="200"
          v-if="[btnDel,btnEdit].indexOf(true) > -1"
        >
          <template slot-scope="scope">
            <el-dropdown>
              <el-button type="primary" size="mini">
                操作<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu>
                <el-dropdown-item><el-button size="mini" @click="editHandle(scope.row)" v-if="btnDel">详细信息</el-button></el-dropdown-item>
                <el-dropdown-item><el-button type="success" size="mini" @click="agreed(scope.row)" v-if="btnDel">通过</el-button></el-dropdown-item>
                <el-dropdown-item><el-button type="warning" size="mini" @click="refused(scope.row)" v-if="btnEdit">驳回</el-button></el-dropdown-item>
                <el-dropdown-item><el-button type="primary" size="mini" @click="entrust(scope.row)" v-if="btnEdit">委托</el-button></el-dropdown-item>
                <el-dropdown-item><el-button type="info" @click="history(scope.row)" size="mini" v-if="btnEdit">历史</el-button></el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <!-- 详细信息 -->
            <!-- <el-button size="mini" @click="editHandle(scope.row)" v-if="btnDel">详细信息</el-button> -->
            <!-- 立即申请 -->
            <!-- <el-button type="success" size="mini" @click="agreed(scope.row)" v-if="btnDel">通过</el-button> -->
            <!-- 重新申请 -->
            <!-- <el-button type="warning" size="mini" @click="refused(scope.row)" v-if="btnEdit">驳回</el-button> -->
            <!-- 修改编辑 -->
            <!-- <el-button type="primary" size="mini" @click="entrust(scope.row)" v-if="btnEdit">委托</el-button> -->
            <!-- 审批历史 -->
            <!-- <el-button type="info" @click="history(scope.row)" size="mini" v-if="btnEdit">历史</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="table-pageblock">
        <!-- current-page 当前页数  page-size 每页显示数 total 总页数-->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[20,50,80,100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>

      <!-- 弹窗 新增or修改 -->
      <el-dialog
        :title="textMap[dialogStatus]"
        :visible.sync="dialogFormVisible"
        :close-on-click-modal="false"
      >
        <!-- 添加、修改表单 -->
        <el-form ref="editForm" :model="editForm" label-width="80px">
          <el-form-item label="委托人">
            <user-sel :users="users" @seluser="selEntrustUser"></user-sel>
          </el-form-item>
          <el-form-item label="审批意见">
            <el-input type="textarea" :rows="3" placeholder="审批意见(20字以内)" v-model="editForm.note"></el-input>
          </el-form-item>
          <!-- <el-form-item label="优先级">
            <el-radio-group v-model="editForm.flowPriority">
              <el-radio label="0">普通</el-radio>
              <el-radio label="1">重要</el-radio>
              <el-radio label="2">紧急</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="消息推送">
            <el-checkbox-group v-model="editForm.msgPush">
              <el-checkbox label="1">站内消息通知</el-checkbox>
              <el-checkbox label="2">企业微信通知</el-checkbox>
              <el-checkbox label="3">邮件通知</el-checkbox>
            </el-checkbox-group>
          </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <!-- 取消 关闭弹窗 -->
          <el-button @click.native="dialogFormVisible=false">取消</el-button>
          <!-- 添加 初始化弹窗表单数据 -->
          <el-button v-if="dialogStatus=='create'" @click="subEntrust" type="primary" :disabled="isSubmit">确认</el-button>
        </div>
      </el-dialog>

      <el-dialog title="流程图" :visible.sync="modalVisible" width="600px">
        <div class="flowLog">
          <el-table
            :data="historyLog"
            border
            style="width: 100%">
            <!-- 处理人 -->
            <el-table-column label="处理人" align="center" width="100">
              <template slot-scope="scope">{{ scope.row.createUserId | getName(users) }}</template>
            </el-table-column>
            <!-- 处理日期 时间格式过滤 -->
            <el-table-column label="处理日期" align="center" width="120">
              <template slot-scope="scope">{{ scope.row.createTime | filterTime }}</template>
            </el-table-column>
            <el-table-column align="center" label="结果" width="60">
              <template slot-scope="scope">
                <!-- 处理结果 1.发起 2.通过 3.驳回 4.取消 -->
                <span v-if="scope.row.result === 1">
                  发起
                </span>
                <span v-if="scope.row.result === 2">
                  通过
                </span>
                <span v-if="scope.row.result === 3">
                  驳回
                </span>
                <span v-if="scope.row.result === 4">
                  取消
                </span>
              </template>
            </el-table-column>
            <el-table-column
              prop="note"
              label="审批说明">
            </el-table-column>
          </el-table>
        </div>
        <node-data ref="nodeFlow" :nodeData="nodeData"></node-data>
      </el-dialog>

      <!-- 弹窗 立项报告 -->
      <el-dialog :visible.sync="dialogProInfoVisible" @close="goBack" :close-on-click-modal="false" :close-on-press-escape="false">
        <div id="single" class="single" ref="single">
          <h5 style="padding-top:0;">立项信息</h5>
          <table>
            <tbody>
              <tr>
                <td class="title">立项时间</td><td>{{ proInfo.createPro }}</td>
              </tr>
              <tr>
                <td class="title">归属部门</td><td>{{ proInfo.deptName }}</td>
              </tr>
              <tr>
                <td class="title">归属公司</td><td>{{ proInfo.compName }}</td>
              </tr>
              <tr>
                <td class="title">客户名称</td><td>{{ proInfo.cusName }}</td>
              </tr>
              <tr>
                <td class="title">客户部门</td><td>{{ proInfo.cusDeptName }}</td>
              </tr>
              <tr>
                <td class="title">项目经理</td><td>{{ proInfo.compDeptUser }}</td>
              </tr>
              <tr>
                <td class="title">项目名称</td><td>{{ proInfo.proName }}</td>
              </tr>
              <tr>
                <td class="title">项目周期</td><td>{{ proInfo.cycleStart }} ~ {{ proInfo.cycleEnd }}</td>
              </tr>
              <tr>
                <td class="title">立项说明</td><td>{{ proInfo.note }}</td>
              </tr>
            </tbody>
          </table>
          <h5>审批记录</h5>
          <table>
            <thead>
              <tr>
                <th class="title2" style="width: 110px;">处理人</th>
                <th class="title2" style="width: 130px;">处理时间</th>
                <th class="title2" style="width: 80px;">处理结果</th>
                <th class="title2" style="text-align:left;">审批意见</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(item, index) in lhistory" :key="index">
                <td style="text-align:center;">{{ item.doUser }}</td>
                <td>{{ item.doTime }}</td>
                <td style="text-align:center;">{{ item.doResult }}</td>
                <td>{{ item.note }}</td>
              </tr>
            </tbody>
          </table>
        </div>
        <div slot="footer" class="tdialog-footer">
          <!-- 图片 -->
          <el-button size="mini" @click="downloadResult" style="float:left;">图片下载</el-button>
          <!-- 打印 -->
          <el-button size="mini" v-print="'single'" style="float:right;">报告打印</el-button>
          <div class="clean-both"></div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
// 引入时间格式化插件
import moment from 'moment';
// 引入html2Canvas
import html2canvas from 'html2canvas';
// 引入员工选择组件
import userSel from '@/components/UserSel/index.vue';
// 节点数据
import NodeData from '@/components/NodeData';

export default {
  // 注册组件
  components: {
    userSel,
    NodeData
  },
  // 父组件传值子组件
  props: {
    // 按钮级权限
    btns: {
      type: Object
    },
    'flowType': String,
    'tabCode': String
  },

  // 无白屏刷新方法注入
  inject: ['reload'],

  // 监听
  watch: {
    // 按钮权限数据
    btns (val, oldVal) {
      // 刷新当前页
      this.reload();
    },
    // 监听流程类型
    flowType: {
      immediate: true,
      handler (newVal, oldVal) {
        this.flowType = newVal;
      }
    },

    // 监听tab类型
    tabCode: {
      handler (newVal, oldVal) {
        if (newVal === 'second') {
          // 加载分页数据
          this.getmenusDataByPage();

          // 获取所有流程模型数据
          this.getFlowList();

          // 获取所有员工
          this.getUsers();
        }
      }
    }
  },

  // 实例创建后执行
  async created () {
    // 按钮级授权
    await this.authorization(this.$store.state.btns);
    this.getmenusDataByPage();
  },

  // 过滤器
  filters: {
    // 时间显示过滤
    filterTime (value) {
      return moment(value).format('YYYY-MM-DD') === 'Invalid date' ? '无' : moment(value).format('YYYY-MM-DD');
    },
    // 发起人过滤
    getName (value, params) {
      for (let i = 0; i < params.length; i++) {
        if (params[i].userId === value) {
          return params[i].userName;
        }
      }
    }
  },

  // 当前页面数据
  data () {
    return {
      // 获取流程类型
      // flowType: this.$route.path.indexOf('/travel') > 1 ? 'CLBXLC-HF-' : this.$route.path.indexOf('/cash') > 1 ? 'XJBXLC-HF-' : this.$route.path.indexOf('/setUp') > 1 ? 'LXSQLC-HF-' : '',
      // 流程图预览数据
      nodeData: {},
      modalVisible: false,
      flowList: [],
      // 审批历史数据
      historyLog: [],
      // 屏蔽重复提交
      isSubmit: false,
      // 按钮显示隐藏  - 默认值
      btnSel: true,
      btnDel: true,
      btnUpload: true,
      btnDown: true,
      btnAdd: true,
      btnEdit: true,

      // 获取所有用户
      users: [],
      // 用户选择框子组件选中值
      getUser: [],
      entrusUser: [],

      // 搜索条件
      formInline: {
        flowCode: '',
        flowOriginator: ''
      },

      // 表单初始化数据
      editForm: {
        // flowPriority: '',
        // msgPush: [],
        note: ''
      },

      // 列表数据
      menusData: [{}],
      // 当前页
      currentPage: 1,
      // 当前数
      pageSize: 20,
      // 总条目数
      total: 20,

      // 弹窗类别
      dialogStatus: '',
      // 弹窗标题
      textMap: {
        edit: '修改信息',
        create: '委托信息'
      },
      // 弹窗是否显示
      dialogFormVisible: false,

      dialogProInfoVisible: false,

      // 项目信息
      proInfo: {},
      // 审批记录
      lhistory: [],
      // 当前申请人所在部门角色池领导
      rolesList: [],
      // 节点压缩后的审批节点，审批人
      globalParams: {
        globalFlowCurrentNode: '',
        globallowCurrentUser: ''
      }
    };
  },

  mounted () {
    // this.getHeight();
    // 增加监听事件，窗口变化时得到高度。
    // window.addEventListener('resize', this.getHeight, false);
  },
  methods: {
    // 表格高度自适应
    // getHeight () {
    // // 获取浏览器高度并计算得到表格所用高度。
    //   this.tableHeight = document.documentElement.clientHeight - 290;
    // },
    // 图片下载
    downloadResult () {
      let _this = this;
      html2canvas(_this.$refs.single, {
        backgroundColor: '#fff'
      }).then(canvas => {
        let imgData = canvas.toDataURL('image/jpeg');
        _this.fileDownload(imgData);
      });
    },

    // 下载图片
    fileDownload (downloadUrl) {
      // let _this = this;
      let aLink = document.createElement('a');
      aLink.style.display = 'none';
      aLink.href = downloadUrl;
      aLink.download = '立项报告.png';
      // 触发点击-然后移除
      document.body.appendChild(aLink);
      aLink.click();
      document.body.removeChild(aLink);
    },

    // 员工工号显示过滤
    filterName: function (value) {
      let _this = this;
      let params = _this.users;
      for (let i = params.length; i--;) {
        if (params[i].userId === value) {
          return params[i].userName + ' [' + value + ']';
        }
      }
    },
    // 审批结果显示过滤
    filterResult: function (value) {
      //  <!-- 处理结果 1.发起 2.通过 3.驳回 4.取消 -->
      if (value === 1) {
        return '发起';
      }
      if (value === 2) {
        return '通过';
      }
      if (value === 3) {
        return '驳回';
      }
      if (value === 4) {
        return '取消';
      }
    },
    // 时间过滤
    filterTimes: function (value) {
      return moment(value).format('YYYY-MM-DD') === 'Invalid date' ? '' : moment(value).format('YYYY-MM-DD HH:mm:ss');
    },
    // 委托他人
    entrust (row) {
      // 弹窗类型
      this.dialogStatus = 'create';
      // 弹窗显示状态
      this.dialogFormVisible = true;

      // 表单数据重置
      this.entrustUser = [];
      // 弹窗表单初始化数据
      this.editForm = Object.assign({}, row);
      // 重置新增界面默认数据
      // this.editForm.flowPriority = '';
      // this.editForm.msgPush = [];
      this.editForm.note = '';
    },

    // 提交委托
    subEntrust () {
      let params = {
        // 工单编号
        flowCode: this.editForm.flowCode,
        // 发起人
        flowOriginator: this.editForm.flowOriginator,
        // 当前审批节点
        flowCurrentNode: this.editForm.flowCurrentNode,
        // 当前审批人
        flowCurrentUser: this.entrusUser[0],
        // 工单状态
        status: 3,
        // 处理结果
        result: this.editForm.flowCurrentNode + ', 流程已委托处理！',
        // 工单优先级
        // flowPriority: this.editForm.flowPriority,
        // 消息推送
        // msgPush: this.editForm.msgPush.toString(),
        // 审批历史-审批节点
        flowNode: this.editForm.flowCurrentNode,
        // 审批历史-审批意见
        note: this.editForm.note,
        // 审批历史-审批结果
        workResult: 2
      };

      this.$http.raw('api/updateOrderStatus', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          this.$message({
            message: '操作成功，已委托处理！',
            type: 'success'
          });
          this.dialogFormVisible = false;
          this.getmenusDataByPage();
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 驳回申请
    refused (row) {
      let _this = this;
      // 工单编号
      let flowCode = row.flowCode;
      // 驳回直接退回到申请人
      let logUser = row.flowOriginator;

      // 收集请求参数
      let userResult = {
        orderCode: flowCode,
        userId: logUser
      };
      // 根据操作历史回溯发起人、发起节点
      _this.$http.raw('/api/findResults', userResult).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          // 发起节点
          let setUpNodeId = [];
          datas.map(item => {
            if (item.result === 1 && item.note === '发起申请') {
              setUpNodeId.push(item.flowNode);
            }
          });
          let params = {
            // 工单编号
            flowCode: row.flowCode,
            // 发起人
            flowOriginator: row.flowOriginator,
            // 当前审批节点
            flowCurrentNode: setUpNodeId[0],
            // 当前审批人
            flowCurrentUser: row.flowOriginator,
            // 工单状态
            status: 5,
            // 处理结果
            result: row.flowCurrentNode + ', 申请被驳回！',
            // 工单优先级
            // flowPriority: row.flowPriority,
            // 消息推送
            // msgPush: row.msgPush,
            // 审批历史-审批节点
            flowNode: row.flowCurrentNode,
            // 审批历史-审批意见
            note: row.note,
            // 审批历史-审批结果
            workResult: 3
          };

          this.$http.raw('api/updateOrderStatus', params).then(res => {
            let { code } = res;
            // 判断Code状态
            if (code === 0) {
              this.$message({
                message: '审批成功，已驳回申请！',
                type: 'success'
              });
              this.getmenusDataByPage();
            }
          }).catch(err => {
            if (err === undefined) {
              this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 通过申请
    agreed (row) {
      let _this = this;
      // 判断当前审批节点 业务审批 | 财务审批
      let flowId = row.flowId;
      let prevNode = row.flowCurrentNode;

      // 立即申请判断当前节点的下一步审批节点
      let params = {
        prevNode,
        flowId
      };
      // 先判断是否是 现金报销流程 | 差旅报销流程
      if (row.flowId.indexOf('LXSQLC') > -1) {
        _this.$http.post('/api/findNextNode', params).then(res => {
          let {code, datas} = res;
          if (code === 0) {
            if (datas.flowType === '结束') {
              _this.lxLastNode(row);
            } else {
              _this.lxNextNode(row, datas);
            }
          }
        }).catch(err => {
          if (err === undefined) {
            this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      } else if (row.flowId.indexOf('XJBXLC') > -1) {
        _this.$http.post('/api/findNextNode', params).then(res => {
          let {code, datas} = res;
          if (code === 0) {
            if (datas.flowNodeName.indexOf('财务') > -1 || datas.flowNodeName.indexOf('付款归档') > -1 || datas.flowNodeName.indexOf('地域出纳') > -1) {
              _this.cashFinancialNextNode(row, datas);
            } else if (datas.flowNodeRole.indexOf('发起人') > -1) {
              _this.cashFinancialNextNode(row, datas);
            } else if (datas.flowType === '结束') {
              _this.toNextEnd(row);
            } else {
              _this.cashToNextNode(row, datas);
            }
          }
        }).catch(err => {
          if (err === undefined) {
            this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      } else if (row.flowId.indexOf('CLBXLC') > -1) {
        _this.$http.post('/api/findNextNode', params).then(res => {
          let {code, datas} = res;
          if (code === 0) {
            if (datas.flowNodeName.indexOf('财务') > -1 || datas.flowNodeName.indexOf('付款归档') > -1 || datas.flowNodeName.indexOf('地域出纳') > -1) {
              _this.cashFinancialNextNode(row, datas);
            } else if (datas.flowNodeRole.indexOf('发起人') > -1) {
              _this.cashFinancialNextNode(row, datas);
            } else if (datas.flowType === '结束') {
              _this.toNextEnd(row);
            } else {
              _this.travelToNextNode(row, datas);
            }
          }
        }).catch(err => {
          if (err === undefined) {
            this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      } else {
        _this.$http.post('/api/findNextNode', params).then(res => {
          let {code, datas} = res;
          if (code === 0) {
            if (datas.flowNodeRole.indexOf('发起人') > -1) {
              _this.backNextNode(row, datas);
            } else if (datas.flowType === '结束') {
              _this.toNextEnd(row);
            } else {
              _this.goNextNode(row, datas);
            }
          }
        }).catch(err => {
          if (err === undefined) {
            this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      }
    },

    // 发起人审批
    backNextNode (row, nextNode) {
      let _this = this;
      let nodes = JSON.parse(row.flowJson).nodes;
      let currentNode = [];
      nodes.map(item => {
        if (item.roles === '发起人') {
          currentNode.push(item);
        }
      });
      if (nextNode.flowNodeRole === '发起人') {
        let params = {
          // 工单编号
          flowCode: row.flowCode,
          // 发起人
          flowOriginator: row.flowOriginator,
          // 当前审批节点
          flowCurrentNode: currentNode[0].id,
          // 当前审批人
          flowCurrentUser: row.flowOriginator,
          // 工单状态
          status: 3,
          // 处理结果
          result: row.flowCurrentNode + ', 审批已通过！',
          // 工单优先级
          // flowPriority: _this.editForm.flowOriginator,
          // 消息推送
          // msgPush: _this.editForm.msgPush.join(','),
          // 审批历史-审批节点
          flowNode: row.flowCurrentNode,
          // 审批历史-审批意见
          note: _this.editForm.note,
          // 审批历史-审批结果
          workResult: 2
        };
        this.$http.raw('api/updateOrderStatus', params).then(res => {
          let { code } = res;
          // 判断Code状态
          if (code === 0) {
            this.$message({
              message: '审批成功，已批准通过！',
              type: 'success'
            });
            _this.getmenusDataByPage();
          }
        }).catch(err => {
          if (err === undefined) {
            this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      }
    },
    // 正常审批结束
    lxLastNode (row) {
      let _this = this;
      let rowDB = JSON.parse(row.flowJson).nodes;
      let tUserId = JSON.parse(row.formJson).tUserId;
      let endNode = [];
      rowDB.map(item => {
        if (item.type === '结束') {
          endNode.push(item.id);
        }
      });

      let params = {
        // 工单编号
        flowCode: row.flowCode,
        // 发起人
        flowOriginator: row.flowOriginator,
        // 当前审批节点
        flowCurrentNode: endNode[0],
        // 当前审批人
        flowCurrentUser: '',
        // 工单状态
        status: 4,
        // 处理结果
        result: row.flowCurrentNode + ', 审批已通过并结束！',
        // 工单优先级
        // flowPriority: '',
        // 消息推送
        // msgPush: '',
        // 审批历史-审批节点
        flowNode: row.flowCurrentNode,
        // 审批历史-审批意见
        note: row.note,
        // 审批历史-审批结果
        workResult: 2
      };

      this.$http.raw('api/updateOrderStatus', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          // 审批结束修改关联项目ID mark状态
          // note: res.datas,
          let proMark = {
            mark: 1,
            proId: row.note
          };
          _this.$http.post('api/updateProMark', proMark).then(res => {
            let { code } = res;
            if (code === 0) {
              this.$message({
                message: '审批成功，已批准通过！',
                type: 'success'
              });
              // 获取项目基本信息
              let params = {
                proId: row.note
              };
              // 获取人天数据
              _this.$http.post('api/findProInfo', params).then(res => {
                let { code, datas } = res;
                if (code === 0) {
                  _this.proInfo = {
                    // 立项时间
                    createPro: moment(datas.proInfo.cycleStart).format('YYYY-MM-DD'),
                    // 归属公司
                    compName: datas.proInfo.compName,
                    // 归属部门
                    deptName: datas.proInfo.deptName,
                    // 客户名称
                    cusName: datas.proInfo.cusName,
                    // 客户部门
                    cusDeptName: datas.proInfo.cusDeptName,
                    // 项目经理
                    compDeptUser: tUserId,
                    // 项目名称
                    proName: datas.proInfo.proName,
                    // 项目周期 - 开始时间
                    cycleStart: moment(datas.proInfo.cycleStart).format('YYYY-MM-DD'),
                    // 项目周期 - 结束时间
                    cycleEnd: moment(datas.proInfo.cycleEnd).format('YYYY-MM-DD'),
                    // 立项说明
                    note: datas.proInfo.note
                  };

                  let flowInfo = {
                    flowCode: row.flowCode
                  };
                  _this.$http.post('api/findWorkResultList', flowInfo).then(res => {
                    let { code, datas } = res;
                    // 判断Code状态
                    if (code === 0) {
                      let logls = [];
                      for (let i = 0; i < datas.length; i++) {
                        logls.push({
                          doUser: _this.filterName(datas[i].createUserId),
                          doTime: _this.filterTimes(datas[i].createTime),
                          doResult: _this.filterResult(datas[i].result),
                          note: datas[i].note
                        });
                      }

                      _this.lhistory = logls;
                      // _this.dialogProInfoVisible = true;

                      // setTimeout(() => {
                      //   // 通过页面生成立项报告并上传
                      //   html2canvas(_this.$refs.single, {
                      //     backgroundColor: '#fff'
                      //   }).then(canvas => {
                      //     let imgData = canvas.toDataURL('image/jpeg');
                      //     let formData = new FormData(); // 创建form对象
                      //     formData.append('base64', imgData);
                      //     _this.$http.upload('api/uploadFileBase64', formData).then(res => {
                      //       let { code, datas } = res;
                      //       if (code === 0) {
                      //         // 上传成功后添加立项报告记录
                      //         let inReport = {
                      //           // 立项报告文件路径
                      //           picUrl: datas,
                      //           // 审批记录
                      //           pJson: JSON.stringify(_this.lhistory),
                      //           // 关联项目ID
                      //           proId: row.note,
                      //           // 备注说明
                      //           note: ''
                      //         };
                      //         _this.$http.raw('api/insertProReport', inReport).then(res => {
                      //           let {code} = res;
                      //           if (code === 0) {
                      //             _this.getmenusDataByPage();
                      //           }
                      //         }).catch(err => {
                      //           if (err === undefined) {
                      //             _this.$message({
                      //               message: '服务器响应异常！',
                      //               type: 'error'
                      //             });
                      //             return false;
                      //           }
                      //         });
                      //       }
                      //     }).catch(err => {
                      //       if (err === undefined) {
                      //         _this.$message({
                      //           message: '服务器响应异常！',
                      //           type: 'error'
                      //         });
                      //         return false;
                      //       }
                      //     });
                      //   });
                      // }, 2000);
                    }
                  }).catch(err => {
                    if (err === undefined) {
                      _this.$message({
                        message: '服务器响应异常！',
                        type: 'error'
                      });
                      return false;
                    }
                  });
                }
              }).catch(err => {
                if (err === undefined) {
                  _this.$message({
                    message: '服务器响应异常！',
                    type: 'error'
                  });
                  return false;
                }
              });
            }
          }).catch(err => {
            if (err === undefined) {
              this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },
    // 正常业务线审批
    lxNextNode (row, nextNode) {
      let _this = this;
      let rowDB = JSON.parse(row.formJson);
      // 部门
      let deptId = rowDB.compDeptUser.code[1];
      let deptRole = {
        deptId
      };
      let nextInfo = nextNode;
      // 判断是否存在审批角色池
      _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          let userLines = {};
          datas.map(item => {
            if (nextInfo.flowNodeRole === item.roleName) {
              userLines = item;
            }
          });
          let params = {
            // 工单编号
            flowCode: row.flowCode,
            // 发起人
            flowOriginator: row.flowOriginator,
            // 当前审批节点
            flowCurrentNode: nextInfo.flowNodeId,
            // 当前审批人
            flowCurrentUser: userLines.userId,
            // 工单状态
            status: 3,
            // 处理结果
            result: row.flowCurrentNode + ', 审批已通过！',
            // 工单优先级
            // flowPriority: row.flowPriority,
            // 消息推送
            // msgPush: row.msgPush,
            // 审批历史-审批节点
            flowNode: row.flowCurrentNode,
            // 审批历史-审批意见
            note: row.note,
            // 审批历史-审批结果
            workResult: 2
          };
          _this.$http.raw('api/updateOrderStatus', params).then(res => {
            let { code } = res;
            // 判断Code状态
            if (code === 0) {
              _this.$message({
                message: '审批成功，已批准通过！',
                type: 'success'
              });
              _this.getmenusDataByPage();
            }
          }).catch(err => {
            if (err === undefined) {
              _this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        }
      });
    },

    // 非正常现金报销审批
    cashFinancialNextNode (row, nextNode) {
      let _this = this;
      // let rowDB = JSON.parse(row.formJson);
      if (nextNode.flowNodeRole === '发起人') {
        let params = {
          // 工单编号
          flowCode: row.flowCode,
          // 发起人
          flowOriginator: row.flowOriginator,
          // 当前审批节点
          flowCurrentNode: nextNode.flowNodeId,
          // 当前审批人
          flowCurrentUser: row.flowOriginator,
          // 工单状态
          status: 3,
          // 处理结果
          result: row.flowCurrentNode + ', 审批已通过！',
          // 工单优先级
          // flowPriority: row.flowPriority,
          // 消息推送
          // msgPush: row.msgPush,
          // 审批历史-审批节点
          flowNode: row.flowCurrentNode,
          // 审批历史-审批意见
          note: row.note,
          // 审批历史-审批结果
          workResult: 2
        };
        this.$http.raw('api/updateOrderStatus', params).then(res => {
          let { code } = res;
          // 判断Code状态
          if (code === 0) {
            this.$message({
              message: '审批成功，已批准通过！',
              type: 'success'
            });
            _this.getmenusDataByPage();
          }
        }).catch(err => {
          if (err === undefined) {
            this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      } else {
        let params = {
          // 工单编号
          flowCode: row.flowCode,
          // 发起人
          flowOriginator: row.flowOriginator,
          // 当前审批节点
          flowCurrentNode: nextNode.flowNodeId,
          // 当前审批人
          flowCurrentUser: nextNode.note,
          // 工单状态
          status: 3,
          // 处理结果
          result: row.flowCurrentNode + ', 审批已通过！',
          // 工单优先级
          // flowPriority: row.flowPriority,
          // 消息推送
          // msgPush: row.msgPush,
          // 审批历史-审批节点
          flowNode: row.flowCurrentNode,
          // 审批历史-审批意见
          note: row.note,
          // 审批历史-审批结果
          workResult: 2
        };
        _this.$http.raw('api/updateOrderStatus', params).then(res => {
          let { code } = res;
          // 判断Code状态
          if (code === 0) {
            _this.$message({
              message: '审批成功，已批准通过！',
              type: 'success'
            });
            _this.getmenusDataByPage();
          }
        }).catch(err => {
          if (err === undefined) {
            _this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      }
    },

    // 正常现金报销审批  (根据审批授权金额，判断是否跳过后续报销业务线审批节点)
    async cashToNextNode (row, nextNode) {
      let _this = this;
      let rowDB = JSON.parse(row.formJson);
      // 判断当前节点角色授权金额是否满足
      let deptId = rowDB.compDeptUser.code[1];
      await this.getRoleList(deptId); // 获取发起申请人部门角色池角色
      await _this.getProcessNextNode(row, nextNode);

      setTimeout(() => {
        let userLines = [];
        let newUser = '';
        _this.rolesList.map(item => {
          if (nextNode.flowNodeRole === item.roleName) {
            newUser = item.userId;
            userLines.push(item);
          }
        });

        // 获取报销金额数
        let arrs = [];
        arrs = rowDB.reimbursementList.map(item => {
          if (item.reimbursementId) {
            return item.subtotal;
          } else {
            return rowDB.sumMoney;
          }
        });
        let totalPrice = Math.max(...arrs);
        // 超出授权额度，下一步
        if (userLines.length > 0 && totalPrice >= userLines[0].money) {
          let users = [];
          // 查找下一步审批人
          _this.rolesList.map(item => {
            if (item.roleName === nextNode.flowNodeRole) {
              users.push(item.userId);
            }
          });
          let params = {
            // 工单编号
            flowCode: row.flowCode,
            // 发起人
            flowOriginator: row.flowOriginator,
            // 当前审批节点
            flowCurrentNode: _this.globalParams.globalFlowCurrentNode,
            // 当前审批人
            flowCurrentUser: _this.globalParams.globallowCurrentUser,
            // 工单状态
            status: 3,
            // 处理结果
            result: row.flowCurrentNode + ', 审批已通过！',
            // 工单优先级
            // flowPriority: row.flowPriority,
            // 消息推送
            // msgPush: row.msgPush,
            // 审批历史-审批节点
            flowNode: row.flowCurrentNode,
            // 审批历史-审批意见
            note: row.note,
            // 审批历史-审批结果
            workResult: 2
          };
          _this.$http.raw('api/updateOrderStatus', params).then(res => {
            let { code } = res;
            // 判断Code状态
            if (code === 0) {
              _this.$message({
                message: '审批成功，已批准通过！',
                type: 'success'
              });
              _this.getmenusDataByPage();
            }
          }).catch(err => {
            if (err === undefined) {
              _this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        } else { // 不超出授权额度，跳至地域出纳审核节点、付款归档节点
          let rowBow = JSON.parse(row.flowJson).nodes;
          let locationUser = newUser;
          let nextNodeFlow = nextNode.flowNodeId;
          rowBow.map(item => {
            if (item.label === '地域出纳审核' && nextNode.flowNodeName.indexOf('付款审批') === -1) {
              // 南京分公司及南京地域的由李妍审核——HF00853S
              // if (this.$store.state.userinfo.location.indexOf('南京') > -1 || this.$store.state.userinfo.compId.indexOf('HFXXN') > -1) {
              //   locationUser = item.users[0];
              // } else { // 其他地域的由王燕燕审核——HF01280S
              //   locationUser = item.users[1];
              // }
              locationUser = item.users.join(',');
              nextNodeFlow = item.id;
            }
            if (item.label === '打印单据' && nextNode.flowNodeName.indexOf('付款审批') > -1) {
              locationUser = row.flowOriginator;
              nextNodeFlow = item.id;
            }
          });
          let params = {
            // 工单编号
            flowCode: row.flowCode,
            // 发起人
            flowOriginator: row.flowOriginator,
            // 当前审批节点
            flowCurrentNode: nextNodeFlow,
            // 当前审批人
            flowCurrentUser: locationUser,
            // 工单状态
            status: 3,
            // 处理结果
            result: row.flowCurrentNode + ', 审批已通过！',
            // 工单优先级
            // flowPriority: row.flowPriority,
            // 消息推送
            // msgPush: row.msgPush,
            // 审批历史-审批节点
            flowNode: row.flowCurrentNode,
            // 审批历史-审批意见
            note: row.note,
            // 审批历史-审批结果
            workResult: 2
          };
          this.$http.raw('api/updateOrderStatus', params).then(res => {
            let { code } = res;
            // 判断Code状态
            if (code === 0) {
              this.$message({
                message: '审批成功，已批准通过！',
                type: 'success'
              });
              _this.getmenusDataByPage();
            }
          }).catch(err => {
            if (err === undefined) {
              this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        }
      }, 1000);
    },

    // 正常财务业务线审批  (根据审批授权金额，判断是否跳过后续报销业务线审批节点)
    async travelToNextNode (row, nextNode) {
      let _this = this;
      let rowDB = JSON.parse(row.formJson);
      // 判断当前节点角色授权金额是否满足
      let deptId = rowDB.compDeptUser.code[1];
      await this.getRoleList(deptId);
      await _this.getProcessNextNode(row, nextNode);

      setTimeout(() => {
        let travelMoney = [];
        travelMoney = rowDB.travelList.map(item => {
          if (item.travelId) {
            return item.subtotal;
          } else {
            return rowDB.sumMoney;
          }
        });
        let totalPrice = Math.max(...travelMoney);
        let userLines = [];
        let newUser = '';
        _this.rolesList.map(item => {
          if (nextNode.flowNodeRole === item.roleName) {
            newUser = item.userId;
            userLines.push(item);
          }
        });
        // 超出授权额度，下一步
        if (userLines.length > 0 && totalPrice >= userLines[0].money) {
          let users = [];
          // 查找下一步审批人
          _this.rolesList.map(item => {
            if (item.roleName === nextNode.flowNodeRole) {
              users.push(item.userId);
            }
          });
          let params = {
            // 工单编号
            flowCode: row.flowCode,
            // 发起人
            flowOriginator: row.flowOriginator,
            // 当前审批节点
            flowCurrentNode: _this.globalParams.globalFlowCurrentNode,
            // 当前审批人
            flowCurrentUser: _this.globalParams.globallowCurrentUser,
            // 工单状态
            status: 3,
            // 处理结果
            result: row.flowCurrentNode + ', 审批已通过！',
            // 工单优先级
            // flowPriority: row.flowPriority,
            // 消息推送
            // msgPush: row.msgPush,
            // 审批历史-审批节点
            flowNode: row.flowCurrentNode,
            // 审批历史-审批意见
            note: row.note,
            // 审批历史-审批结果
            workResult: 2
          };
          _this.$http.raw('api/updateOrderStatus', params).then(res => {
            let { code } = res;
            // 判断Code状态
            if (code === 0) {
              _this.$message({
                message: '审批成功，已批准通过！',
                type: 'success'
              });
              _this.getmenusDataByPage();
            }
          }).catch(err => {
            if (err === undefined) {
              _this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        } else { // 不超出授权额度，跳至财务节点
          let rowBow = JSON.parse(row.flowJson).nodes;
          let locationUser = newUser;
          let nextNodeFlow = nextNode.flowNodeId;
          rowBow.map(item => {
            if (item.label === '地域出纳审核' && nextNode.flowNodeName.indexOf('付款审批') === -1) {
              // 南京分公司及南京地域的由李妍审核——HF00853S
              // if (this.$store.state.userinfo.location.indexOf('南京') > -1 || this.$store.state.userinfo.compId.indexOf('HFXXN') > -1) {
              //   locationUser = item.users[0];
              // } else { // 其他地域的由王燕燕审核——HF01280S
              //   locationUser = item.users[1];
              // }
              locationUser = item.users.join(',');
              nextNodeFlow = item.id;
            }
            if (item.label === '打印单据' && nextNode.flowNodeName.indexOf('付款审批') > -1) {
              locationUser = row.flowOriginator;
              nextNodeFlow = item.id;
            }
          });
          let params = {
            // 工单编号
            flowCode: row.flowCode,
            // 发起人
            flowOriginator: row.flowOriginator,
            // 当前审批节点
            flowCurrentNode: nextNodeFlow,
            // 当前审批人
            flowCurrentUser: locationUser,
            // 工单状态
            status: 3,
            // 处理结果
            result: row.flowCurrentNode + ', 审批已通过！',
            // 工单优先级
            // flowPriority: row.flowPriority,
            // 消息推送
            // msgPush: row.msgPush,
            // 审批历史-审批节点
            flowNode: row.flowCurrentNode,
            // 审批历史-审批意见
            note: row.note,
            // 审批历史-审批结果
            workResult: 2
          };
          this.$http.raw('api/updateOrderStatus', params).then(res => {
            let { code } = res;
            // 判断Code状态
            if (code === 0) {
              this.$message({
                message: '审批成功，已批准通过！',
                type: 'success'
              });
              _this.getmenusDataByPage();
            }
          }).catch(err => {
            if (err === undefined) {
              this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        }
      }, 1000);
    },
    // 正常业务线审批  (根据审批授权天数，判断是否跳过审批节点)
    goNextNode (row, nextNode) {
      let _this = this;
      let rowDB = JSON.parse(row.formJson);
      // 部门
      let deptId = rowDB.compDeptUser.code[1];
      let deptRole = {
        deptId
      };
      // 判断当前节点角色授权金额是否满足
      _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          let userLines = [];
          datas.map(item => {
            if (row.flowCurrentUser === item.userId) {
              userLines.push(item);
            }
          });
          // 超出授权天数，下一步
          if ((rowDB.sumDays * 8 + rowDB.sumHours) > (userLines[0].daySize * 8)) {
            let users = [];
            // 查找下一步审批人
            datas.map(item => {
              if (item.roleName === nextNode.flowNodeRole) {
                users.push(item.userId);
              }
            });
            let params = {
              // 工单编号
              flowCode: row.flowCode,
              // 发起人
              flowOriginator: row.flowOriginator,
              // 当前审批节点
              flowCurrentNode: nextNode.flowNodeId,
              // 当前审批人
              flowCurrentUser: users.join(','),
              // 工单状态
              status: 3,
              // 处理结果
              result: row.flowCurrentNode + ', 审批已通过！',
              // 工单优先级
              // flowPriority: _this.editForm.flowPriority,
              // 消息推送
              // msgPush: _this.editForm.msgPush.join(','),
              // 审批历史-审批节点
              flowNode: row.flowCurrentNode,
              // 审批历史-审批意见
              note: row.note,
              // 审批历史-审批结果
              workResult: 2
            };
            _this.$http.raw('api/updateOrderStatus', params).then(res => {
              let { code } = res;
              // 判断Code状态
              if (code === 0) {
                _this.$message({
                  message: '审批成功，已批准通过！',
                  type: 'success'
                });
                _this.getmenusDataByPage();
              }
            }).catch(err => {
              if (err === undefined) {
                _this.$message({
                  message: '服务器响应异常！',
                  type: 'error'
                });
                return false;
              }
            });
          } else { // 不超出授权天数，跳至发起人节点
            let nodes = JSON.parse(row.flowJson).nodes;
            let currentNode = [];
            nodes.map(item => {
              if (item.roles === '发起人') {
                currentNode.push(item);
              }
            });
            let params = {
              // 工单编号
              flowCode: row.flowCode,
              // 发起人
              flowOriginator: row.flowOriginator,
              // 当前审批节点
              flowCurrentNode: currentNode[0].id,
              // 当前审批人
              flowCurrentUser: row.flowOriginator,
              // 工单状态
              status: 3,
              // 处理结果
              result: row.flowCurrentNode + ', 审批已通过！',
              // 工单优先级
              // flowPriority: _this.editForm.flowOriginator,
              // 消息推送
              // msgPush: _this.editForm.msgPush.join(','),
              // 审批历史-审批节点
              flowNode: row.flowCurrentNode,
              // 审批历史-审批意见
              note: row.note,
              // 审批历史-审批结果
              workResult: 2
            };
            this.$http.raw('api/updateOrderStatus', params).then(res => {
              let { code } = res;
              // 判断Code状态
              if (code === 0) {
                this.$message({
                  message: '审批成功，已批准通过！',
                  type: 'success'
                });
                _this.getmenusDataByPage();
              }
            }).catch(err => {
              if (err === undefined) {
                this.$message({
                  message: '服务器响应异常！',
                  type: 'error'
                });
                return false;
              }
            });
          }
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 正常财务业务线审批  (根据审批授权金额，判断是否跳过后续报销业务线审批节点)
    toNextNode (row, nextNode) {
      let _this = this;
      let rowDB = JSON.parse(row.formJson);
      // 公司
      let compId = rowDB.compDeptUser.code[0];
      // 部门
      let deptId = rowDB.compDeptUser.code[1];
      let deptRole = {
        deptId
      };
      // 判断当前节点角色授权金额是否满足
      _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          let userLines = [];
          datas.map(item => {
            if (row.flowCurrentUser === item.userId) {
              userLines.push(item);
            }
          });
          // 超出授权额度，下一步
          if (userLines.length > 0 && rowDB.sumMoney > userLines[0].money) {
            let users = [];
            // 查找下一步审批人
            datas.map(item => {
              if (item.roleName === nextNode.flowNodeRole) {
                users.push(item.userId);
              }
            });
            let params = {
              // 工单编号
              flowCode: row.flowCode,
              // 发起人
              flowOriginator: row.flowOriginator,
              // 当前审批节点
              flowCurrentNode: nextNode.flowNodeId,
              // 当前审批人
              flowCurrentUser: users.join(','),
              // 工单状态
              status: 3,
              // 处理结果
              result: row.flowCurrentNode + ', 审批已通过！',
              // 工单优先级
              // flowPriority: rowDB.flowPriority,
              // 消息推送
              // msgPush: row.msgPush,
              // 审批历史-审批节点
              flowNode: row.flowCurrentNode,
              // 审批历史-审批意见
              note: row.note,
              // 审批历史-审批结果
              workResult: 2
            };
            this.$http.raw('api/updateOrderStatus', params).then(res => {
              let { code } = res;
              // 判断Code状态
              if (code === 0) {
                this.$message({
                  message: '审批成功，已批准通过！',
                  type: 'success'
                });
                this.getmenusDataByPage();
              }
            }).catch(err => {
              if (err === undefined) {
                this.$message({
                  message: '服务器响应异常！',
                  type: 'error'
                });
                return false;
              }
            });
          } else { // 不超出授权额度，跳至财务节点
            let deptRole = {
              deptId: ''
            };
            if (compId === 'STSBJ') {
              deptRole.deptId = 'BJ-CWB';
            }
            if (compId === 'STSGZ') {
              deptRole.deptId = 'GZ-CWB';
            }
            if (compId === 'STSNJ') {
              deptRole.deptId = 'NJ-CWB';
            }
            if (compId === 'STSSH') {
              deptRole.deptId = 'SH-CWB';
            }
            _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
              let { code, datas } = res;
              // 判断Code状态
              if (code === 0) {
                let flowJson = JSON.parse(row.flowJson).nodes;
                let users = [];
                let next = [];
                flowJson.map(item => {
                  if (item.roles === '财务会计') {
                    next.push(item.id);
                  }
                });
                // 查找下一步审批人
                datas.map(item => {
                  if (item.roleName === '财务会计') {
                    users.push(item.userId);
                  }
                });
                let params = {
                  // 工单编号
                  flowCode: row.flowCode,
                  // 发起人
                  flowOriginator: row.flowOriginator,
                  // 当前审批节点
                  flowCurrentNode: next[0],
                  // 当前审批人
                  flowCurrentUser: users.join(','),
                  // 工单状态
                  status: 3,
                  // 处理结果
                  result: row.flowCurrentNode + ', 审批已通过！',
                  // 工单优先级
                  // flowPriority: rowDB.flowPriority,
                  // 消息推送
                  // msgPush: row.msgPush,
                  // 审批历史-审批节点
                  flowNode: row.flowCurrentNode,
                  // 审批历史-审批意见
                  note: row.note,
                  // 审批历史-审批结果
                  workResult: 2
                };
                this.$http.raw('api/updateOrderStatus', params).then(res => {
                  let { code } = res;
                  // 判断Code状态
                  if (code === 0) {
                    this.$message({
                      message: '审批成功，已批准通过！',
                      type: 'success'
                    });
                    this.getmenusDataByPage();
                  }
                }).catch(err => {
                  if (err === undefined) {
                    this.$message({
                      message: '服务器响应异常！',
                      type: 'error'
                    });
                    return false;
                  }
                });
              }
            }).catch(err => {
              if (err === undefined) {
                this.$message({
                  message: '服务器响应异常！',
                  type: 'error'
                });
                return false;
              }
            });
          }
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 正常审批结束
    toNextEnd (row) {
      let rowDB = JSON.parse(row.flowJson).nodes;
      let endNode = [];

      rowDB.map(item => {
        if (item.type === '结束') {
          endNode.push(item.id);
        }
      });

      let params = {
        // 工单编号
        flowCode: row.flowCode,
        // 发起人
        flowOriginator: row.flowOriginator,
        // 当前审批节点
        flowCurrentNode: endNode[0],
        // 当前审批人
        flowCurrentUser: '',
        // 工单状态
        status: 4,
        // 处理结果
        result: row.flowCurrentNode + ', 审批已通过并结束！',
        // 工单优先级
        // flowPriority: '',
        // 消息推送
        // msgPush: '',
        // 审批历史-审批节点
        flowNode: row.flowCurrentNode,
        // 审批历史-审批意见
        note: '',
        // 审批历史-审批结果
        workResult: 2
      };

      this.$http.raw('api/updateOrderStatus', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          this.$message({
            message: '审批成功，已批准通过！',
            type: 'success'
          });
          this.getmenusDataByPage();
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 结束节点的时候保存数据
    saveData (row, type) {
      let rowFormJson = JSON.parse(row.formJson);
      // 需求人ID
      let demanderId = rowFormJson.demander ? rowFormJson.demander[0].split('-') : '';

      // 业务流水号
      let newBusinessNo = row.flowCode ? row.flowCode : '';
      // 请购评估说明
      let newNote = rowFormJson.evaluate ? rowFormJson.evaluate : '';
      // 预估总额
      let newMoney = rowFormJson.estimatedTotal ? rowFormJson.estimatedTotal : '';
      // 员工编号
      let oldUserName = rowFormJson.compDeptUser ? rowFormJson.compDeptUser.value : '';
      let newUserName = oldUserName ? oldUserName.substring(oldUserName.lastIndexOf('>') + 1) : '';
      // 员工姓名
      let newUserId = row.createUserId ? row.createUserId : '';
      let newCompName = '';
      let newCompDeptName = rowFormJson.compDeptUser ? rowFormJson.compDeptUser.value : '';
      if (type === 3) {
        newNote = rowFormJson.demand;
      } else if (type === 2) {
        newBusinessNo = rowFormJson.turnoverNum;
      } else if (type === 6 || type === 7) {
        newUserId = demanderId[1];
        newUserName = demanderId[0];
        newMoney = rowFormJson.price;
        newCompName = rowFormJson.supplierName;
        newCompDeptName = rowFormJson.demandDept;
        newNote = '';
      }
      let saveParams = {
        businessNo: newBusinessNo,
        type: type,
        money: newMoney,
        userId: newUserId,
        userName: newUserName,
        flowJson: row.flowJson,
        compName: newCompName,
        compDeptName: newCompDeptName,
        note: newNote
      };
      this.$http.raw('api/insertPurchase', saveParams).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          this.getmenusDataByPage();
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },
    getCls (data) {
      this.drawer = data;
    },

    // 获取所有用户
    getUsers () {
      let _this = this;
      let params = {
        status: ''
      };
      _this.$http.post('api/findAllBaseUsers', params).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          _this.users = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 获取用户选择框选中值
    selUser (data) {
      this.getUser = data;
    },

    selEntrustUser (data) {
      this.entrusUser = data;
    },

    editHandle: function (row) {
      let params = {
        flowId: row.flowId
      };
      this.$http.post('api/findFlowRouter', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          this.$router.push({
            path: res.datas,
            query: {
              node: 3,
              datas: row
            }
          });
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 获取所有流程数据
    getFlowList: function () {
      this.$http.raw('api/findAllFlow').then(res => {
        let { code, datas } = res;
        if (code === 0) {
          this.flowList = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 按钮级授权
    authorization (data) {
      for (let i in data) {
        if (data['sel'] === 0) {
          this.btnSel = false;
          return this.btnSel;
        }
        if (data['add'] === 0) {
          this.btnAdd = false;
          return this.btnAdd;
        }
        if (data['del'] === 0) {
          this.btnDel = false;
          return this.btnDel;
        }
        if (data['upload'] === 0) {
          this.btnUpload = false;
          return this.btnUpload;
        }
        if (data['down'] === 0) {
          this.btnDown = false;
          return this.btnDown;
        }
        if (data['edit'] === 0) {
          this.btnEdit = false;
          return this.btnEdit;
        }
        return i;
      }
    },

    // 审批历史
    history: function (row) {
      let params = {
        flowCode: row.flowCode
      };
      this.$http.post('api/findWorkResultList', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          let currentNode = row.flowCurrentNode;
          let flowJson = JSON.parse(row.flowJson);
          flowJson.nodes.map(item => {
            if (item.id === currentNode) {
              item.color = '#FF0000';
            }
          });
          // 流程图预览
          this.modalVisible = true;
          this.nodeData = flowJson;
          this.historyLog = res.datas;
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 查询
    selHandle: function () {
      // 收集请求数据
      let params = {
        flowId: this.flowType,
        flowCode: this.formInline.flowCode,
        flowOriginator: this.getUser[0],
        pageNum: this.currentPage,
        pageSize: this.pageSize
      };
      // 根据公司ID请求对应分页数据结果
      this.$http.raw('api/findOrderByFlowIdAndOUser', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          // 总页数
          this.total = datas.total;
          // 数据结果集
          this.menusData = datas.list;
          // 解决删除当前页数据后仍留在那一页 不跳回上一页的bug
          if (!datas.list.length && this.currentPage !== 1) {
            // 当前页减一
            this.currentPage -= 1;
            // 调用自己
            this.getmenusDataByPage();
          }
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 刷新页面数据
    getmenusDataByPage () {
      // 收集请求参数
      let params = {
        flowId: this.flowType,
        flowCode: '',
        flowOriginator: '',
        pageNum: this.currentPage,
        pageSize: this.pageSize
      };

      this.$http.raw('api/findOrderByFlowIdAndOUser', params).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          // 总页数
          this.total = datas.total;
          this.$emit('upcomefun', this.total);
          // 数据结果集
          this.menusData = datas.list;
          // 解决删除当前页数据后仍留在那一页 不跳回上一页的bug
          if (!datas.list.length && this.currentPage !== 1) {
            // 当前页减一
            this.currentPage -= 1;
            // 调用自己
            this.getmenusDataByPage();
          }
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 每页显示的条数改变
    handleSizeChange (val) {
      this.pageSize = val;
      // 调用刷新页面
      this.getmenusDataByPage();
    },
    // 当前页码
    handleCurrentChange (val) {
      this.currentPage = val;
      // 调用
      this.getmenusDataByPage();
    },
    // 查出当前申请人所在部门角色池领导
    getRoleList (deptId) {
      let _this = this;
      // 当前登录人信息
      let deptRole = {
        deptId: deptId
      };
      return _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          _this.rolesList = JSON.parse(JSON.stringify(datas));
          return _this.rolesList;
        }
      });
    },
    // 中间同意过程的连续节点压缩
    getProcessNextNode (row, nextNode) {
      let _this = this;
      let firstFlowNodeId = nextNode.flowNodeId;
      let firstRoleList = [];
      _this.rolesList.map(item => {
        if (item.roleName === nextNode.flowNodeRole) {
          firstRoleList.push(item.userId);
          _this.firstNextRole = JSON.parse(JSON.stringify(item.userId)); // 下一节点审核人id
        }
      });
      if (nextNode.flowNodeName.indexOf('财务') > -1 || nextNode.flowNodeName.indexOf('付款归档') > -1 || nextNode.flowNodeName.indexOf('地域出纳') > -1) {
        _this.cashFinancialNextNode(row, nextNode);
      }
      // 要求再找下一个节点
      let params = {
        flowId: _this.flowType,
        prevNode: nextNode.flowNodeId
      };
      // 通过当前人所在节点  流程编号 查询下一步审批节点
      return _this.$http.post('/api/findNextNode', params).then(res => {
        let {code} = res;
        if (code === 0) {
          let secondRoleList = [];
          _this.rolesList.map(item => {
            if (item.roleName === res.datas.flowNodeRole) {
              secondRoleList.push(item.userId);
              _this.secondNextRole = JSON.parse(JSON.stringify(item.userId)); // 下一节点审核人id
            }
          });
          if (firstRoleList.length && secondRoleList.length && _this.firstNextRole === _this.secondNextRole) {
            this.getProcessNextNode(row, res.datas);
          } else {
            _this.globalParams = {
              globalFlowCurrentNode: firstFlowNodeId,
              globallowCurrentUser: _this.firstNextRole
            };
            return _this.globalParams;
          }
        }
      });
    }
  }
};
</script>

<style lang='scss'>
@import './index.scss';
</style>
